function sendRequest() {
  const input = document.querySelector('[type="file"]')
  if (input.files.length === 0) return

  const formData = new FormData()
  formData.append('file', input.files[0])

  const xhr = new XMLHttpRequest()
  xhr.open('POST', 'http://127.0.0.1/api/post/uploadFile')
  // 传输进度事件监听
  xhr.upload.onprogress = event => {
    if (event.lengthComputable) {
      var percentage = Math.floor((event.loaded * 100) / event.total)
      console.log('onprogress', percentage)
    }
  }
  // 传输完成事件监听
  xhr.upload.onload = () => {
    console.log('onload')
  }
  xhr.onreadystatechange = () => {
    if (xhr.readyState === XMLHttpRequest.DONE) {
      if (xhr.status === 200) {
        const res = xhr.response
        console.log(res)
      }
    }
  }
  xhr.send(formData)
}
